// pages/cases/detail.js
var api = require('../../utils/api.js');
var WxParse = require('../../wxParse/wxParse.js');
var diyparams= require('../../utils/data.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail:[],
    citys:[]
  },
  callphonenum() {
    wx.makePhoneCall({
      phoneNumber: '4001529288'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loaddetail(options.id);
    this.loadswiper();
    this.setData({
      paramsname: diyparams.params
    });
    this.dialog = this.selectComponent("#mydialog");
    this.loadcitys();
  },

  loaddetail(id) {
    api.get({
      url: 'portal/articles/articles_detail?id='+id,
      success: data => {
        if (data.code == '1') {
          WxParse.wxParse('articleContent', 'html', data.data.articles.post_content, this, 30);
          this.setData({
            detail: data.data.articles,
            adviser: data.data.adviser
          })
        }
      }
    })
  },

  yuyuefunc(e) {
    this.dialog.showModal();
  },
  _hideModal() {
    this.dialog.hideModal();
  },
  formSubmit(e) {
    //提交表单数据
    api.post({
      url: '/portal/diyform/insert',
      data: e.detail.value,
      success: data => {
        if (data.code == "1") {
          wx.showToast({ title: '报名成功', icon: 'success' })
          this.dialog.hideModal();
        }
        if (data.code == "0") {
          wx.showToast({ title: data.msg, icon: 'none' })
        }
      }
    })
  },

  loadswiper() {
    api.get({
      url: 'home/slides/8',
      success: data => {
        if (data.code == 1) {
          this.setData({
            movies: data.data[0].items
          })
        }
      }
    });
  },

  loadcitys() {
    api.get({
      url: 'home/attribute/11',
      success: data => {
        if (data.code == 1) {
          this.dialog.setparam(data.data[0].items);
          this.setData({
            citys: data.data[0].items
          })
        }
      }
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})